package io.renren.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.TApiDeployinfoEntity;
import io.renren.service.TApiDeployinfoService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;


/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-11-27 10:48:55
 */
@RestController
@RequestMapping("tapideployinfo")
public class TApiDeployinfoController {
	@Autowired
	private TApiDeployinfoService tApiDeployinfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("tapideployinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TApiDeployinfoEntity> tApiDeployinfoList = tApiDeployinfoService.queryList(query);
		int total = tApiDeployinfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tApiDeployinfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("tapideployinfo:info")
	public R info(@PathVariable("id") Integer id){
		TApiDeployinfoEntity tApiDeployinfo = tApiDeployinfoService.queryObject(id);
		
		return R.ok().put("tApiDeployinfo", tApiDeployinfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("tapideployinfo:save")
	public R save(@RequestBody TApiDeployinfoEntity tApiDeployinfo){
		tApiDeployinfoService.save(tApiDeployinfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("tapideployinfo:update")
	public R update(@RequestBody TApiDeployinfoEntity tApiDeployinfo){
		tApiDeployinfoService.update(tApiDeployinfo);
		
		return R.ok();
	}
	/**
	 * 启用
	 */
	@RequestMapping("/enable/{id}")
	@RequiresPermissions("tapideployinfo:enable")
	public R enable(@PathVariable("id") Integer id){
		TApiDeployinfoEntity tApiDeployinfo = new TApiDeployinfoEntity();
		tApiDeployinfo.setId(id);
		tApiDeployinfo.setStatus(TApiDeployinfoEntity.STATUS_ENABLE);
		tApiDeployinfoService.enable(tApiDeployinfo);
		return R.ok();
	}
	/**
	 * 禁用
	 */
	@RequestMapping("/disable/{id}")
	@RequiresPermissions("tapideployinfo:disable")
	public R disable(@PathVariable("id") Integer id){
		TApiDeployinfoEntity tApiDeployinfo = new TApiDeployinfoEntity();
		tApiDeployinfo.setId(id);
		tApiDeployinfo.setStatus(TApiDeployinfoEntity.STATUS_DISABLE);
		tApiDeployinfoService.disable(tApiDeployinfo);
		return R.ok();
	}
	/**
	 * 授权
	 */
	@RequestMapping("/ekbauth/{verifyCode}/{id}")
	@RequiresPermissions("tapideployinfo:gettoken")
	public R ekbauth(@PathVariable("id") Integer id,@PathVariable("verifyCode") String verifyCode){
		TApiDeployinfoEntity tApiDeployinfo = new TApiDeployinfoEntity();
		tApiDeployinfo.setId(id);
		tApiDeployinfo.setVertifyCode(verifyCode);
		tApiDeployinfoService.auth(tApiDeployinfo);
		return R.ok();
	}
	/**
	 * 测试
	 */
	@RequestMapping("/testekbservice/{id}")
	@RequiresPermissions("tapideployinfo:testservice")
	public R testservice(@PathVariable("id") Integer id){
		return R.ok().put("data", tApiDeployinfoService.testservice(id));
	}
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("tapideployinfo:delete")
	public R delete(@RequestBody Integer[] ids){
		tApiDeployinfoService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
